package xlcao.sohutv.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;



public class ProgramDownloader {
	private String html = "";

	public ProgramDownloader(String url) {
	}

	public void startDownload() {
		// mHandler = new Handler();
		checkUpdate.start();
	}

	private Thread checkUpdate = new Thread() {
		public void run() {
	
			try {
				String htmlContent = "";
				InputStream inputStream;

				java.net.URL url;
				url = new java.net.URL("http://live.tv.sohu.com/jmyg");
				HttpURLConnection connection = (HttpURLConnection) url
						.openConnection();

				connection.connect();
				inputStream = connection.getInputStream();
				byte bytes[] = new byte[1024 * 100];
				int index = 0;
				int count = inputStream.read(bytes, index, 1024 * 100);
				while (count != -1) {
					index += count;
					count = inputStream.read(bytes, index, 1);
				}
				//System.out.println(count);
				htmlContent = new String(bytes, "gb2312");//
				String temp1 = htmlContent.substring(htmlContent.indexOf("{\"data\"",2));
				String temp2 = temp1.substring(0,htmlContent.indexOf("}]}]};"));
				//htmlContent.substring(htmlContent.indexOf("var data2 = "));
				System.out.println(temp2);
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
	};

}
